package com.longma.server.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.longma.server.pojo.UserResponseEntity;
import com.longma.server.pojo.dto.PageRequestDTO;
import com.longma.server.pojo.vo.AlarmRecordVO;
import com.longma.server.service.IAlarmRecordService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author HAIBO
 * @since 2021-04-28
 */
@RestController
@Validated
@RequestMapping("/api/alarm-record")
public class AlarmRecordController {
    @Autowired
    private IAlarmRecordService alarmRecordService;

    @GetMapping("/checkbymail")
    public String checkByMail(@NotBlank(message = "code不能为空") @RequestParam(name = "code") String code){
        return alarmRecordService.handleAlarmRecordByMail(code);
    }

    @ApiOperation(value = "删除报警记录")
    @PostMapping("/delete")
    public UserResponseEntity<Boolean> delete(@NotNull(message = "告警记录id不能为空")  @RequestParam(name = "id") Integer id){
        return UserResponseEntity.success(alarmRecordService.deleteAlarmRecord(id));
    }

    @ApiOperation(value = "获取所有报警记录(分页)")
    @PostMapping("/list")
    public UserResponseEntity<IPage<AlarmRecordVO>> getAlarmRecordByPage(@ApiParam(value = "分页参数",required = true) @Valid @RequestBody PageRequestDTO pageRequestDTO){
        return UserResponseEntity.success(alarmRecordService.getAlarmRecordByPage(pageRequestDTO.getPageNum(),
                pageRequestDTO.getPageSize(),pageRequestDTO.getAll(),pageRequestDTO.getConditions()));
    }

}

